package com.mz.ozy.activity.me;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;


import com.mz.ozy.R;
import com.mz.ozy.base.BaseActivity;
import com.mz.ozy.bean.MeBean;
import com.mz.ozy.bean.MsgBean;
import com.mz.ozy.bean.MsgDetailBean;
import com.mz.ozy.bean.OrderMsgBean;
import com.mz.ozy.bean.UnreadMsgBean;
import com.mz.ozy.mvp.presenter.MsgPresenter;
import com.mz.ozy.mvp.view.MsgContract;

import org.json.JSONObject;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MsgDetailActivity extends BaseActivity<MsgContract.View, MsgPresenter> implements MsgContract.View {

    @BindView(R.id.msgTitleTv)
    TextView mMsgTitleTv;
    @BindView(R.id.msgTimeTv)
    TextView mMsgTimeTv;
    @BindView(R.id.webview)
    WebView mWebview;
    private int id;
    private String title;
    private String time;
    private String content;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_msg_detail);
        ButterKnife.bind(this);
        initTitle();
        tvTitle.setVisibility(View.GONE);
        tvCenterTitle.setText("详情");
        id = getIntent().getIntExtra("id", 0);
        title = getIntent().getStringExtra("title");
        time = getIntent().getStringExtra("time");
        content = getIntent().getStringExtra("content");
//        mMsgTitleTv.setText(title);
//        mMsgTimeTv.setText(time);
//        mWebview.loadDataWithBaseURL(null, setHtmlContent(content), "text/html", "utf-8", null);
        mPresenter.getMsgDetail(this, String.valueOf(id));

    }

    @Override
    public void getMsgrListSuccess(MsgBean bean) {

    }

    @Override
    public void getOrderMsgrListSuccess(OrderMsgBean bean) {

    }

    @Override
    public void getUnreadMsgSuccess(UnreadMsgBean bean) {

    }

    @Override
    public void getMsgDetailSuccess(MsgDetailBean msgDetailBean) {
        final MsgDetailBean.MsgMapBean map = msgDetailBean.getMap();
        if (map != null) {
            mMsgTitleTv.setText(map.getTitle());
            mMsgTimeTv.setText("时间：" + map.getCreated());
            mWebview.loadDataWithBaseURL(null, setHtmlContent(map.getContent()), "text/html", "utf-8", null);
        }
    }

    @Override
    public void getAgmentDetailSuccess(JSONObject jsonObject) {
    }

    @Override
    public void getgetMeInfoSuccess(MeBean bean) {

    }

    public String setHtmlContent(String contents) {
        String head = ("<head>" +
                "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\"> "
                +
                "<style>img{max-width: 100%; width:auto; height:auto;} body{word-break:break-all;background-color:white}</style>"
                +
                "</head>");
        return "<html>" + head + "<body style=\"word-wrap:break-word;\">" + contents + "</body>" + "</html>";
    }


}
